﻿using System;
using System.Linq;
using System.Collections.Generic;

using Kunlun.Models;

namespace Kunlun.BusinessLogic
{
    public partial class KunlunHelp
    {
        /// <summary>
        /// 获取帮助实体
        /// </summary>
        /// <param name="hid">帮助ID</param>
        public static Help GetHelpModel(int hid)
        {
            using (KunLunEntities entities = new KunLunEntities())
            {
                var model = entities.Help.FirstOrDefault(m => m.Hid == hid);

                if (model != null && model.Status == true)
                    return model;
                return new Help();
            }
        }

        /// <summary>
        /// 获取帮助列表
        /// </summary>
        /// <param name="tid">帮助类别ID</param>
        /// <returns></returns>
        public static List<Help> GetHelpList(int tid)
        {
            using (KunLunEntities entities = new KunLunEntities())
            {
                var model = entities.Help.Where(m => m.Tid == tid).Where(m => m.Status == true);
                if (model != null)
                    return model.ToList();
                return new List<Help>();
            }
        }

		public static List<Help> GetHelpList() {
			using (KunLunEntities entities = new KunLunEntities()) {
				var model = entities.Help.Where(m => m.Status == true);
				if (model != null)
					return model.ToList();
				return new List<Help>();
			}
		}
        /// <summary>
        /// 获取所有帮助类别
        /// </summary>
		public static List<Helptype> GetAllHelptype()
		{
			KunLunEntities entities = new KunLunEntities();

			var model = entities.Helptype.Where(m => m.IsPub).OrderBy(m => m.Orders);
			if (model != null)
				return model.ToList();

			return new List<Helptype>();
		}

        /// <summary>
        /// 获取新闻实体
        /// </summary>
        /// <param name="nid">新闻ID</param>
        public static News GetNewsModel(int nid)
        {
            using (KunLunEntities entities = new KunLunEntities())
            {
                var model = entities.News.FirstOrDefault(m => m.ID == nid);
                if (model != null)
                    return model;
                return new News();
                        
            }
        }

        /// <summary>
        /// 获取所有新闻动态
        /// </summary>
        public static List<News> GetAllNews()
        {
            using (KunLunEntities entities = new KunLunEntities())
            {
                var model = entities.News.Where(m => m.IsPub == true);
                if (model != null)
                    return model.ToList();
                return new List<News>();
            }
        }

        /// <summary>
        /// 获取新闻动态的分页信息
        /// </summary>
        /// <param name="start"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static List<News> GetPageListNews(int start, int size,out int count)
        {
            using (KunLunEntities entities = new KunLunEntities())
            {
                IQueryable<News> query = entities.News.Where(m => m.IsPub == true).OrderByDescending(m => m.LastUpdateTime);
                count = query.Count();
                if (start != 0)
                {
                    query = query.Skip(start * size);
                }
                if (size != 0)
                {
                    query = query.Take(size);
                }

                return query.ToList();
            }
        }

		public static List<FriendLink> GetLinks() {
			using (KunLunEntities entities = new KunLunEntities()) {
				return entities.FriendLink.OrderBy(o => o.Orders).ToList();
			}
		}




		#region  暂时没有用的方法

		/// <summary>
		/// 获取帮助类别实体
		/// </summary>
		/// <param name="tid">帮助类别</param>
		public static Helptype GetHelptypeModel(int tid)
		{
			using (KunLunEntities entities = new KunLunEntities())
			{
				var model = entities.Helptype.FirstOrDefault(m => m.Tid == tid);
				if (model != null)
					return model;
				return new Helptype();
			}
		}

		#endregion


	}
}
